<template>
  <div>
    <window ref="win">
      <div ref="refundDocIframe"></div>
      <div class="btns">
        <el-button
          @click="goPrev"
          v-if="current>0"
        >
          上一个
        </el-button>
        <el-button
          type="success"
          @click="print"
        >打印</el-button>
        <el-button
          @click="goNext"
          v-if="maxCurrent>current"
        >
          下一个
        </el-button>
      </div>
    </window>
  </div>

</template>

<script>
import io from '../../lib/io'
import Pagination from '../base/Pagination'

export default {
  data: function() {
    return {
      tableData: [],
      studentRefundId: '',
      current: 0,
      dialogVisible: false,
      studentRefundList: [],
      maxCurrent: 0
    }
  },
  mounted: function() {
    $(window).smoothScroll()
  },
  created: function() {},
  methods: {
    loadTableData() {
      this.$showLoading()
      io.post(
        io.studentRefundsWithRegInfoDetails,
        {
          studentRefundIds: this.studentRefundId
        },
        ret => {
          this.$hiddenLoading()
          if (ret.success) {
            this.studentRefundList = ret.data
            this.maxCurrent =
              this.studentRefundList.length - 1 > 0
                ? this.studentRefundList.length - 1
                : 0
            for (let item of this.studentRefundList) {
              item.studentRefund.createTime = this.$options.filters.formatTime(
                item.studentRefund.createTime
              )
              item.studentRefund.updateTime = this.$options.filters.formatTime(
                item.studentRefund.updateTime
              )
              item.createTime = this.$options.filters.formatDate(
                item.createTime
              )
              item.auditTime = this.$options.filters.formatDate(item.auditTime)
            }
            this.postIframeData()
          } else {
            this.$alert(ret.desc)
          }
        }
      )
    },
    postIframeData() {
      sessionStorage.setItem(
        'refundDetail',
        JSON.stringify(this.studentRefundList[this.current])
      )
      this.getIframe()
    },
    goNext() {
      this.current++
      if (this.current > this.maxCurrent) {
        this.current = this.maxCurrent
      }
      this.postIframeData()
    },
    goPrev() {
      this.current--
      if (this.current < 0) {
        this.current = 0
      }
      this.postIframeData()
    },
    getIframe() {
      let src = '../../static/cert/refund.html?time=' + new Date().getTime()
      $(this.$refs.refundDocIframe).html(
        '<iframe ref="withdrawDoc" height="1000px" src=' +
          src +
          ' width="100%" frameborder="0"></iframe>'
      )
    },
    show: function() {
      // this.dialogVisible = true
      this.$refs.win.show({
        width: 900,
        height: 1130
      })
      this.loadTableData()
    },
    print() {
      var frame = $(this.$refs.refundDocIframe).find('iframe')[0]
      frame.contentWindow.focus()
      frame.contentWindow.print()
    }
  }
}
</script>
<style lang="less" scoped>
.btns {
  width: 100%;
  display: flex;
  justify-content: center;
}
</style>


